package com.kawa.kemanage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kawa.kemanage.entity.NewsDetail;
import com.kawa.kemanage.mapper.NewsMapper;
import com.kawa.kemanage.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Author: KAIyo
 * @Date: 2025/6/3 0:28
 * @Version: v1.0.0
 * @Description: TODO
 **/
@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;

    /**
     * 根据类型，文章标题，发布时间,查询所有新闻
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public PageInfo<NewsDetail> findAllNews(Integer pageNum, Integer pageSize, Integer categoryId, String title, Date beginDate, Date endDate) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<NewsDetail> pageInfo = new PageInfo<>(newsMapper.findAllNews(categoryId, title, beginDate, endDate));
        return pageInfo;
    }


    /**
     * 根据id查询新闻
     * @param id
     * @return
     */
    @Override
    public NewsDetail getNewsById(Long id) {
        return newsMapper.getNewsById(id);
    }
    /**
     * 新增新闻
     * @param newsDetail
     * @return
     */
    @Override
    public int addNews(NewsDetail newsDetail) {
        return newsMapper.addNews(newsDetail);
    }
/**
     * 根据id修改新闻
     * @param news
     * @return
     */
    public boolean updateNewsById(NewsDetail news) {
        return newsMapper.updateNewsById(news) > 0;
    }

    /**
     * 根据id删除新闻
     * @param id
     * @return
     *
     * */
    @Override
    public boolean delNewsById(Integer id) {
        return newsMapper.delNewsById(id) > 0;
    }

}
